//
//  YXForumCell.m
//  CreditCard
//
//  Created by 杨旭 on 2017/12/30.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "YXForumCell.h"
#import "YXPostModel.h"
#import "YXForumVideoView.h"
#import "YXForumPictureView.h"
@interface YXForumCell ()

@property (weak, nonatomic) IBOutlet UIImageView *picImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLab;
@property (weak, nonatomic) IBOutlet UILabel *timeLab;
@property (weak, nonatomic) IBOutlet UILabel *titleLab;
@property (weak, nonatomic) IBOutlet UILabel *contentLab;
@property (strong, nonatomic) YXForumVideoView *videoView;
@property (strong, nonatomic) YXForumPictureView *pictureView;
@end

@implementation YXForumCell

- (void)dealloc {
    NSLog(@"cell 被销毁");
}


- (YXForumVideoView *)videoView {
    if (!_videoView) {
        _videoView = [[YXForumVideoView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 150)];
    }
    return _videoView;
}
-(YXForumPictureView *)pictureView {
    if (!_pictureView) {
        _pictureView = [[YXForumPictureView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 100)];
        [self.contentView addSubview:_pictureView];
    }
    return _pictureView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setModel:(YXPostModel *)model {
    _model = model;
    [_picImageView sd_setImageWithURL:[NSURL URLWithString:_model.portraitImgUrl] placeholderImage:[UIImage imageNamed:@""]];
    _nameLab.text = model.nickname;
    _titleLab.text = [NSString stringWithFormat:@"%@",_model.title];
    _timeLab.text = [UILabel formateData:_model.createTime];
    [_likeBtn setTitle:_model.collectCount forState:(UIControlStateNormal)];
    [_replyBtn setTitle:_model.replyCount forState:(UIControlStateNormal)];
    _likeBtn.selected = _model.isCollect;

    
    
    if ([_model.type isEqualToString:@"0"]) { // 图片
        self.videoView.hidden = YES;
        self.contentLab.hidden = YES;
        self.pictureView.hidden = NO;
        self.pictureView.frame = _model.contentF;
        [self.contentView addSubview:self.pictureView];
    }else if ([_model.type isEqualToString:@"1"]) { // 视频
        self.pictureView.hidden = YES;
        self.contentLab.hidden = YES;
        self.videoView.hidden = NO;
        self.videoView.frame = _model.contentF;
        [self.contentView addSubview:self.videoView];
    }else if ([_model.type isEqualToString:@"2"]) { // 文字
        self.videoView.hidden = YES;
        self.pictureView.hidden = YES;
        self.contentLab.hidden = NO;
        self.contentLab.frame = _model.contentF;
        self.contentLab.text = _model.contents;
        
    }
    
}




@end
